package com.atguigu.gmallre.mock.service.impl;


import com.atguigu.gmallre.mock.bean.*;
import com.atguigu.gmallre.mock.config.AppConfig;
import com.atguigu.gmallre.mock.mapper.*;
import com.atguigu.gmallre.mock.service.*;
import com.atguigu.gmallre.mock.service.adv.impl.AdvServiceImpl;

import com.atguigu.mock.util.RandomNumBuilder;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 库存单元表 服务实现类
 * </p>
 *
 * @author zc
 * @since 2020-02-23
 */
@Service
public class SkuInfoServiceImpl extends AdvServiceImpl<SkuInfoMapper, SkuInfo> implements SkuInfoService {



    public SkuInfo getSkuInfoById(List<SkuInfo> skuInfoList, Long skuId){
        for (SkuInfo skuInfo : skuInfoList) {
            if(skuInfo.getId().equals(skuId)){
                return skuInfo;
            }
        }
        return null;
    }



    @PostConstruct
    public void initSkuRandomBuilder(){

        Integer[] tmWeightFemale = AppConfig.tmWeightFemale;
        Integer[] tmWeightMale = AppConfig.tmWeightMale;

        AppConfig.skuRandomBuilderF= new RandomNumBuilder();
        AppConfig.skuRandomBuilderM= new RandomNumBuilder();

        Map<Long, SkuInfo> skuInfoMap = all(true);
        for (Map.Entry<Long, SkuInfo> skuInfoEntry : skuInfoMap.entrySet()) {
            SkuInfo skuInfo = skuInfoEntry.getValue();
            int tmId = skuInfo.getTmId().intValue();
            int  femaleWeight  = tmWeightFemale[tmId - 1];
            int  maleWeight  = tmWeightMale[tmId - 1];
            AppConfig.skuRandomBuilderF.addNum(skuInfo.getId().intValue(),femaleWeight);
            AppConfig.skuRandomBuilderM.addNum(skuInfo.getId().intValue(),maleWeight);
        }
    }







}
